<template>
  <div class="live-List">
    <TopBar></TopBar>
    <SecondaryBanner :bannerData="liveBannerList"></SecondaryBanner>

    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item class="clickable-item"
                            :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>互动</el-breadcrumb-item>
        <el-breadcrumb-item class="now-link clickable-item">直播</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="content-wrapper">
      <ul class="content">
        <li class="content-item"
            :class="{
            'to-start': cItem.flag === 3,
            'in-execution': cItem.flag === 2,
            'has-ended': cItem.flag === 1,
          }"
            v-for="(cItem, cIndex) in contentData"
            :key="cIndex"
            @click="addCount(cItem)">
          <div class="item-img-wrapper">
            <img :src="cItem.backgroundImage"
                 alt="" />
            <div class="item-status"></div>
          </div>
          <div class="item-time-wrapper">
            <div class="item-time">
              <span class="item-time-text"
                    v-if="!isPhone">直播时间:</span>
              {{ cItem.startTime }} {{ cItem.endTime }}
            </div>
          </div>
          <h3 class="item-title">{{ cItem.title }}</h3>
        </li>

        <div class="pagination">
          <el-pagination background
                         layout="prev, pager, next"
                         @current-change="currentChange"
                         @prev-click="prevClick"
                         @next-click="nextClick"
                         :page-count="totalPage"
                         :page-size="pageSize">
          </el-pagination>
        </div>
      </ul>
    </div>

    <Footer></Footer>
  </div>
</template>

<script>
import SecondaryBanner from "../components/commonComponent/secondaryBanner";
import Footer from "./commonComponent/footer.vue";
import TopBar from "./commonComponent/topBar.vue";
import { mapActions, mapState } from "vuex";
export default {
  name: "liveList",
  data () {
    return {
      isPhone: false,
      screenWidth: document.body.clientWidth,
      pagerCount: 7,
      // contentData: [
      //   {
      //     id: 1,
      //     type: 1,
      //     title: "开源线上活动",
      //     source: "",
      //     content: "基金会开源线上活动简介",
      //     textDetails: "",
      //     advertiseImage: require("../assets/images/content-item.png"),
      //     advertiseUrl: "https:www.baidu.com",
      //     startTime: "2020.02.24",
      //     endTime: "2022.02.25",
      //     label: 1,
      //     recommend: 1,
      //     likesCount: 100,
      //     shareCount: 200,
      //     browseCount: 300,
      //   },
      //   {
      //     id: 1,
      //     type: 1,
      //     title: "开源线上活动",
      //     source: "",
      //     content: "基金会开源线上活动简介",
      //     textDetails: "",
      //     advertiseImage: require("../assets/images/content-item.png"),
      //     advertiseUrl: "https:www.baidu.com",
      //     startTime: "2020.02.24",
      //     endTime: "2022.02.25",
      //     label: 1,
      //     recommend: 1,
      //     likesCount: 100,
      //     shareCount: 200,
      //     browseCount: 300,
      //   },
      //   {
      //     id: 1,
      //     type: 1,
      //     title: "开源线上活动",
      //     source: "",
      //     content: "基金会开源线上活动简介",
      //     textDetails: "",
      //     advertiseImage: require("../assets/images/content-item.png"),
      //     advertiseUrl: "https:www.baidu.com",
      //     startTime: "2020.02.24",
      //     endTime: "2022.02.25",
      //     label: 1,
      //     recommend: 1,
      //     likesCount: 100,
      //     shareCount: 200,
      //     browseCount: 300,
      //   },
      //   {
      //     id: 1,
      //     type: 1,
      //     title: "开源线上活动",
      //     source: "",
      //     content: "基金会开源线上活动简介",
      //     textDetails: "",
      //     advertiseImage: require("../assets/images/content-item.png"),
      //     advertiseUrl: "https:www.baidu.com",
      //     startTime: "2020.02.24",
      //     endTime: "2022.02.25",
      //     label: 1,
      //     recommend: 1,
      //     likesCount: 100,
      //     shareCount: 200,
      //     browseCount: 300,
      //   },
      //   {
      //     id: 1,
      //     type: 1,
      //     title: "开源线上活动",
      //     source: "",
      //     content: "基金会开源线上活动简介",
      //     textDetails: "",
      //     advertiseImage: require("../assets/images/content-item.png"),
      //     advertiseUrl: "https:www.baidu.com",
      //     startTime: "2020.02.24",
      //     endTime: "2022.02.25",
      //     label: 1,
      //     recommend: 1,
      //     likesCount: 100,
      //     shareCount: 200,
      //     browseCount: 300,
      //   },
      //   {
      //     id: 1,
      //     type: 1,
      //     title: "开源线上活动",
      //     source: "",
      //     content: "基金会开源线上活动简介",
      //     textDetails: "",
      //     advertiseImage: require("../assets/images/content-item.png"),
      //     advertiseUrl: "https:www.baidu.com",
      //     startTime: "2020.02.24",
      //     endTime: "2022.02.25",
      //     label: 1,
      //     recommend: 1,
      //     likesCount: 100,
      //     shareCount: 200,
      //     browseCount: 300,
      //   },
      // ],
      pageSize: 6,
      pageNum: 1,
      category: 1,
    };
  },
  components: {
    SecondaryBanner,
    Footer,
    TopBar,
  },
  computed: {
    ...mapState({
      contentData: (state) => state.subData.liveBatchList,
      liveBannerList: (state) => state.subBanner.liveBannerList,

      totalPage: (state) => state.subData.totalPage,
    }),
  },
  methods: {
    ...mapActions(["getQueryCarousel", "getQueryBatch"]),
    async addCount (item) {
      let res = await this.$axios.post(
        `/knowledge/secondaryPage/updateCount?id=${item.id}&type=1`
      );

      await this.getQueryBatch({
        type: 4,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      });

      this.$nextTick(() => {
        let u = navigator.userAgent;
        let isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1;
        let isIos = !!u.match(/\(i[^;]+;(U;)? CPU.+Mac OS X/);
        console.log(item);
        if (item.url) {
          if (isIos) {
            window.location.href = item.url;
          } else {
            window.open(item.url);
          }
        }
      })
    },
    //直播
    //当前页
    currentChange (item) {
      this.pageNum = item;
      this.getQueryBatch({
        type: 4,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      });
      console.log(item);
    },
    //上一页
    prevClick (item) {
      this.pageNum = item;
      this.getQueryBatch({
        type: 4,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      });
      console.log(item);
    },
    //下一页
    nextClick (item) {
      this.pageNum = item;
      this.getQueryBatch({
        type: 4,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      });
      console.log(item);
    },
  },
  watch: {
    screenWidth (newVal) {
      if (newVal < 768) {
        this.isPhone = true;
        this.pagerCount = 5;
      } else {
        this.isPhone = false;
        this.pagerCount = 7;
      }
    },
    // $route: {
    //   handler(newVal) {
    //     if (newVal.query.id == 5) {
    //       this.isLive = false;
    //     } else if (newVal.query.id == 4) {
    //       this.isLive = true;
    //     }
    //   },
    //   deep: true,
    //   immediate: true,
    // },
  },
  created () {
    let phonewid = document.documentElement.clientWidth < 768;
    if (this.$route.query.id == 5) {
      this.isLive = false;
    } else if (this.$route.query.id == 4) {
      this.isLive = true;
    }
    if (document.documentElement.clientWidth < 768) {
      this.isPhone = true;
      this.pagerCount = 5;
    } else {
      this.isPhone = false;
      this.pagerCount = 7;
    }
    if (phonewid) {
      this.category = 2;
    } else {
      this.category = 1;
    }
    this.getQueryBatch({
      type: this.$route.query.id,
      pageNum: this.pageNum,
      pageSize: this.pageSize,
    });
    let currentId = this.$route.query.id;
    this.getQueryCarousel({
      type: this.$route.query.id,
      category: this.category,
      currentId: currentId,
    });
  },
  mounted () {
    const that = this;
    window.onresize = () => {
      return (() => {
        window.screenWidth = document.body.clientWidth;
        that.screenWidth = window.screenWidth;
      })();
    };
  },
};
</script>

<style scoped lang="less">
@media screen and (min-width: 1032px) {
  .base {
    width: 1032px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  .live-List {
    /deep/.breadcrumb {
      .base;
      height: 28px;
      padding: 16px 0 16px 0;
      justify-content: flex-start;
      align-items: center;
      .el-breadcrumb__inner {
        font-size: 14px;
        font-family: HarmonyOS_Sans_SC;
        color: rgba(0, 0, 0, 0.45);
      }
      .el-breadcrumb__inner.is-link {
        font-weight: 400;
      }
      .now-link {
        .el-breadcrumb__inner {
          color: rgba(0, 0, 0, 0.65);
        }
      }
      .clickable-item {
        &:hover {
          .el-breadcrumb__inner {
            color: #00a6f9;
          }
        }
      }
    }

    .content-wrapper {
      background: #fafafa;
      .content {
        .base;
        justify-content: flex-start;
        flex-wrap: wrap;
        padding-top: 40px;
        .content-item {
          width: 31%;
          padding-bottom: 16px;
          margin-right: 24px;
          margin-bottom: 24px;
          background: #fff;
          border-radius: 8px;
          cursor: pointer;
          &:hover {
            position: relative;
            top: -8px;
            box-shadow: 0px 12px 24px 0px rgba(0, 0, 0, 0.06);
          }
          &:nth-child(3n) {
            margin-right: 0;
          }
          .item-img-wrapper {
            width: 100%;
            height: 216px;
            position: relative;
            border-radius: 8px 8px 0 0;
            img {
              width: 100%;
              height: 100%;
              border-radius: 8px 8px 0 0;
            }
            .item-status {
              width: 68px;
              height: 25px;
              position: absolute;
              right: 0;
              top: 0;
            }
          }
          .item-time-wrapper {
            width: 259px;
            height: 30px;
            line-height: 30px;
            margin: 23px 0 19px 0;
            .item-time {
              margin-left: 16px;
              font-family: HarmonyOS_Sans_Condensed_Medium;
              .item-time-text {
                font-family: HarmonyOS_Sans_SC_Medium;
              }
            }
          }
          .item-title {
            height: 56px;
            line-height: 28px;
            padding: 0 16px;
            margin: 32px 0 12px 0;
            font-size: 20px;
            font-family: HarmonyOS_Sans_SC;
            color: rgba(0, 0, 0, 0.85);
            word-break: normal;
            word-wrap: break-word;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-box-pack: center;
            -webkit-box-align: center;
            -webkit-line-clamp: 2;
          }
        }
        // 判断状态待开始,进行中,已结束
        .to-start {
          .item-status {
            background: url("../assets/images/live-item-aready.png");
            background-size: contain;
          }
          .item-time-wrapper {
            background: url("../assets/images/live-aready-background.png")
              no-repeat 100% 100%;
            .item-time {
              color: #84b329;
            }
          }
        }
        .in-execution {
          .item-status {
            background: url("../assets/images/live-item-running.png");
            background-size: contain;
          }
          .item-time-wrapper {
            background: url("../assets/images/live-running-background.png")
              no-repeat 100% 100%;
            .item-time {
              color: #00a6f9;
            }
          }
        }
        .has-ended {
          .item-status {
            background: url("../assets/images/live-item-finish.png");
            background-size: contain;
          }
          .item-time-wrapper {
            .item-time {
              color: rgba(0, 0, 0, 0.45);
            }
          }
        }
      }
    }
    /deep/.pagination {
      width: 100%;
      margin-bottom: 48px;
      .el-pagination {
        float: right;
        .number,
        .btn-prev,
        .btn-next,
        .btn-quickprev,
        .btn-quicknext {
          width: 32px;
          height: 32px;
          padding: 0;
          font-size: 14px;
          font-family: HelveticaNeue;
          background: #ffffff;
          border-radius: 2px;
          border: 1px solid rgba(0, 0, 0, 0.12);
        }
      }
      .el-pagination.is-background .el-pager li:not(.disabled).active {
        background: #242933;
        opacity: 0.9;
      }
    }
  }
}
@media screen and (min-width: 768px) and (max-width: 1032px) {
  .base {
    width: 768px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  .live-List {
    /deep/.breadcrumb {
      .base;
      height: 28px;
      padding: 16px 0 16px 0;
      justify-content: flex-start;
      align-items: center;
      .el-breadcrumb__inner {
        font-size: 14px;
        font-family: HarmonyOS_Sans_SC;
        color: rgba(0, 0, 0, 0.45);
      }
      .el-breadcrumb__inner.is-link {
        font-weight: 400;
      }
      .now-link {
        .el-breadcrumb__inner {
          color: rgba(0, 0, 0, 0.65);
        }
      }
      .clickable-item {
        &:hover {
          .el-breadcrumb__inner {
            color: #00a6f9;
          }
        }
      }
    }
    .content-wrapper {
      background: #fafafa;
      .content {
        padding: 36px 36px 0;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        .content-item {
          justify-content: flex-start;
          width: 48%;
          padding-bottom: 16px;
          margin-bottom: 24px;
          background: #fff;
          border-radius: 8px;
          cursor: pointer;
          &:hover {
            position: relative;
            top: -8px;
            box-shadow: 0px 12px 24px 0px rgba(0, 0, 0, 0.06);
          }
          &:nth-child(2n) {
            margin-right: 0;
          }
          .item-img-wrapper {
            width: 100%;
            height: 216px;
            position: relative;
            border-radius: 8px 8px 0 0;
            img {
              width: 100%;
              height: 100%;
              border-radius: 8px 8px 0 0;
            }
            .item-status {
              width: 68px;
              height: 25px;
              position: absolute;
              right: 0;
              top: 0;
            }
          }
          .item-time-wrapper {
            width: 259px;
            height: 30px;
            line-height: 30px;
            margin: 23px 0 19px 0;
            .item-time {
              margin-left: 16px;
              font-family: HarmonyOS_Sans_Condensed_Medium;
              .item-time-text {
                font-family: HarmonyOS_Sans_SC_Medium;
              }
            }
          }
          .item-title {
            width: 100%;
            box-sizing: border-box;
            height: 56px;
            line-height: 28px;
            padding: 0 16px;
            margin: 32px 0 12px 0;
            font-size: 20px;
            font-family: HarmonyOS_Sans_SC;
            color: rgba(0, 0, 0, 0.85);
            word-break: normal;
            word-wrap: break-word;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-box-pack: center;
            -webkit-box-align: center;
            -webkit-line-clamp: 2;
          }
        }
        // 判断状态待开始,进行中,已结束
        .to-start {
          .item-status {
            background: url("../assets/images/live-item-aready.png");
            background-size: contain;
          }
          .item-time-wrapper {
            background: url("../assets/images/live-aready-background.png")
              no-repeat 100% 100%;
            .item-time {
              color: #84b329;
            }
          }
        }
        .in-execution {
          .item-status {
            background: url("../assets/images/live-item-running.png");
            background-size: contain;
          }
          .item-time-wrapper {
            background: url("../assets/images/live-running-background.png")
              no-repeat 100% 100%;
            .item-time {
              color: #00a6f9;
            }
          }
        }
        .has-ended {
          .item-status {
            background: url("../assets/images/live-item-finish.png");
            background-size: contain;
          }
          .item-time-wrapper {
            .item-time {
              color: rgba(0, 0, 0, 0.45);
            }
          }
        }
      }
    }
    /deep/.pagination {
      width: 100%;
      margin-bottom: 48px;
      display: flex;
      justify-content: center;
      .el-pagination {
        float: right;
        .number,
        .btn-prev,
        .btn-next,
        .btn-quickprev,
        .btn-quicknext {
          width: 32px;
          height: 32px;
          padding: 0;
          font-size: 14px;
          font-family: HelveticaNeue;
          background: #ffffff;
          border-radius: 2px;
          border: 1px solid rgba(0, 0, 0, 0.12);
        }
      }
      .el-pagination.is-background .el-pager li:not(.disabled).active {
        background: #242933;
        opacity: 0.9;
      }
    }
  }
}
@media screen and (max-width: 768px) {
  .base {
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }
  .live-List {
    /deep/.breadcrumb {
      .base;
      height: 28px;
      padding: 13px 0 13px 12px;
      justify-content: flex-start;
      align-items: center;
      .el-breadcrumb__inner {
        font-size: 14px;
        font-family: HarmonyOS_Sans_SC;
        color: rgba(0, 0, 0, 0.45);
      }
      .el-breadcrumb__inner.is-link {
        font-weight: 400;
      }
      .now-link {
        .el-breadcrumb__inner {
          color: rgba(0, 0, 0, 0.65);
        }
      }
      .clickable-item {
        &:hover {
          .el-breadcrumb__inner {
            color: #00a6f9;
          }
        }
      }
    }
    .content-wrapper {
      background: #fafafa;
      .content {
        .base;
        flex-wrap: wrap;
        justify-content: space-between;
        padding: 12px 12px 0;
        .content-item {
          width: 48%;
          padding-bottom: 16px;
          margin-bottom: 12px;
          background: #fff;
          border-radius: 8px;
          .item-img-wrapper {
            width: 100%;
            position: relative;
            border-radius: 8px 8px 0 0;
            img {
              width: 100%;
              border-radius: 8px 8px 0 0;
            }
            .item-status {
              width: 68px;
              height: 25px;
              position: absolute;
              right: 0;
              top: 0;
            }
          }
          .item-time-wrapper {
            width: 158px;
            height: 30px;
            line-height: 30px;
            margin: 23px 0 19px 0;
            .item-time {
              font-size: 12px;
              margin-left: 16px;
              font-family: HarmonyOS_Sans_Condensed_Medium;
            }
          }
          .item-title {
            padding: 0 16px;
            margin: 16px 0 16px;
            height: 66px;
            font-size: 16px;
            font-family: HarmonyOS_Sans_SC_Medium;
            color: rgba(0, 0, 0, 0.85);
            line-height: 22px;
            word-break: normal;
            word-wrap: break-word;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-box-pack: center;
            -webkit-box-align: center;
            -webkit-line-clamp: 3;
          }
        }
        // 判断状态待开始,进行中,已结束
        .to-start {
          .item-status {
            background: url("../assets/images/live-item-aready.png");
          }
          .item-time-wrapper {
            background: url("../assets/images/phone-live-aready.png") no-repeat
              100% 100%;
            .item-time {
              color: #84b329;
            }
          }
        }
        .in-execution {
          .item-status {
            background: url("../assets/images/live-item-running.png");
            background-size: contain;
          }
          .item-time-wrapper {
            background: url("../assets/images/phone-live-running.png") no-repeat
              100% 100%;
            .item-time {
              color: #00a6f9;
            }
          }
        }
        .has-ended {
          .item-status {
            background: url("../assets/images/live-item-finish.png");
            background-size: contain;
          }
          .item-time-wrapper {
            .item-time {
              color: rgba(0, 0, 0, 0.45);
            }
          }
        }
      }
    }
    /deep/.pagination {
      width: 100%;
      margin: 12px 0 40px;
      .el-pagination {
        float: right;
        .number,
        .btn-prev,
        .btn-next,
        .btn-quickprev,
        .btn-quicknext {
          width: 32px;
          height: 32px;
          padding: 0;
          font-size: 14px;
          font-family: HelveticaNeue;
          background: #ffffff;
          border-radius: 2px;
          border: 1px solid rgba(0, 0, 0, 0.12);
        }
      }
      .el-pagination.is-background .el-pager li:not(.disabled).active {
        background: #242933;
        opacity: 0.9;
      }
    }
  }
}
</style>
